<?php
if (null !== $this->grid) {
	/* @var $grid KontorX_DataGrid */
	$grid = $this->grid;
	
	/* @var $urlParams KontorX_View_Helper_UrlParams */
	$urlParams = $this->getHelper('UrlParams');
	$start = $urlParams->get('start', $grid->getPageNumber());
	$limit = $urlParams->get('limit', $grid->getItemCountPerPage());

	$grid->setPageNumber($start/$limit + 1);
	$grid->setItemCountPerPage($limit);

	/* @var KontorX_DataGrid_Adapter_DbSelect */
	$adapter = $grid->getAdapter();
	$adapter->setCellsetClass('KontorX_DataGrid_Adapter_Cellset_ExtGrid');
	$rowset = $adapter->toArray();

	$data = array(
		'success' => true,
		'count' => $grid->getPaginator()->getTotalItemCount(),
		'rowset' => $rowset
	);

	print $this->json($data);
}